<?php
$printTemplateArray = $this->adminHelper()->erpPrintTemplateState('payable');
if ($printTemplateArray['state']) echo $this->partial('admin/print-template/inCss');
?>
<div class="content-wrapper">
    <section class="content-header">
        <?php echo $this->partial('layout/breadcrumb'); ?>

        <h1 class="pull-right">
            <a href="<?php echo $this->url('finance-payable');?>" class="btn btn-default btn-sm"><i class="fa fa-arrow-left"></i> <?php echo $this->translate('返回应付账款列表'); ?></a>
            <button type="button" onclick="<?php echo $printTemplateArray['state'] ? 'directPrint()' : 'toPrint()'; ?>;" class="btn btn-primary btn-sm"><i class="fa fa-print" aria-hidden="true"></i> <?php echo $this->translate('点击打印'); ?></button>
            <?php echo $this->HelpUrl('financePayableView'); ?>
        </h1>
    </section>

    <section class="content">

        <div class="row">
            <div class="col-md-12" id="to-print-info">
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title"><?php echo $this->translate('应付账款'); ?></h3>
                    </div>

                    <div class="box-body">
                        <div class="row">
                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <b><?php echo $this->translate('入库单号'); ?>：</b><?php echo $this->escapeHtml($this->warehouseOrder->getWarehouseOrderSn());?>
                                </div>
                            </div>

                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <b><?php echo $this->translate('仓库'); ?>：</b><?php echo $this->escapeHtml($this->warehouseOrder->getOneWarehouse()->getWarehouseName());?>
                                </div>
                            </div>

                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <b><?php echo $this->translate('状态'); ?>：</b><?php echo $this->PurchaseHelper()->orderState($this->warehouseOrder->getWarehouseOrderState());?>
                                </div>
                            </div>

                        </div>

                        <div class="row">
                            <div class="col-xs-12 form-group">
                                <div class="col-sm-12">
                                    <b><?php echo $this->translate('入库备注'); ?>：</b><?php echo $this->escapeHtml($this->warehouseOrder->getWarehouseOrderInfo());?>
                                </div>
                            </div>
                        </div>

                        <hr />
                        <div class="row">
                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <b><?php echo $this->translate('采购单号'); ?>：</b><?php echo $this->escapeHtml($this->orderInfo->getPOrderSn());?>
                                </div>
                            </div>

                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <b><?php echo $this->translate('供应商'); ?>：</b><?php echo $this->escapeHtml($this->orderInfo->getOneSupplier()->getSupplierName());?>
                                </div>
                            </div>

                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <b><?php echo $this->translate('付款方式'); ?>：</b><?php echo $this->PurchaseHelper()->orderPayment($this->orderInfo->getPaymentCode());?>
                                </div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <b><?php echo $this->translate('供应商联系人'); ?>：</b><?php echo $this->escapeHtml($this->orderInfo->getSupplierContacts());?>
                                </div>
                            </div>

                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <b><?php echo $this->translate('供应商手机'); ?>：</b><?php echo $this->escapeHtml($this->orderInfo->getSupplierPhone());?>
                                </div>
                            </div>

                            <div class="col-xs-4 form-group">
                                <div class="col-sm-12">
                                    <b><?php echo $this->translate('供应商座机'); ?>：</b><?php echo $this->escapeHtml($this->orderInfo->getSupplierTelephone());?>
                                </div>
                            </div>
                        </div>

                        <div class="row">
                            <div class="col-xs-12 form-group">
                                <div class="col-sm-12">
                                    <b><?php echo $this->translate('备注'); ?>：</b><?php echo $this->escapeHtml($this->orderInfo->getPOrderInfo());?>
                                </div>
                            </div>
                        </div>

                        <div class="box-header">
                            <h4 class="box-title"><?php echo $this->translate('采购商品'); ?></h4>
                        </div>
                        <div class="box-body table-responsive no-padding">
                            <table class="table table-hover">
                                <thead>
                                <tr>
                                    <th width="15%"><?php echo $this->translate('商品编号'); ?></th>
                                    <th width="20%"><?php echo $this->translate('商品名称'); ?></th>
                                    <th><?php echo $this->translate('商品规格'); ?></th>
                                    <th><?php echo $this->translate('单位'); ?></th>
                                    <th><?php echo $this->translate('采购单价'); ?></th>
                                    <th><?php echo $this->translate('采购数量'); ?></th>
                                    <th width="10%"><?php echo $this->translate('采购总价'); ?></th>
                                </tr>
                                </thead>

                                <?php if($this->warehouseOrder->getWarehouseOrderState() == 3) { ?>
                                    <?php foreach ($this->orderGoods as $goodsValue) { ?>
                                        <tr>
                                            <td><?php echo $this->escapeHtml($goodsValue->getGoodsNumber()); ?></td>
                                            <td><?php echo $this->escapeHtml($goodsValue->getGoodsName()); ?></td>
                                            <td><?php echo $this->escapeHtml($goodsValue->getGoodsSpec()); ?></td>
                                            <td><?php echo $this->escapeHtml($goodsValue->getGoodsUnit()); ?></td>
                                            <td><?php echo $this->erpCurrencyFormat($goodsValue->getWarehouseGoodsPrice()); ?></td>
                                            <td><?php echo $goodsValue->getWarehouseGoodsBuyNum(); ?></td>
                                            <td><?php echo $this->erpCurrencyFormat($goodsValue->getWarehouseGoodsAmount()); ?></td>
                                        </tr>
                                    <?php } ?>
                                <?php } else { ?>
                                    <?php foreach ($this->orderGoods as $goodsValue) { ?>
                                        <tr>
                                            <td><?php echo $this->escapeHtml($goodsValue->getGoodsNumber()); ?></td>
                                            <td><?php echo $this->escapeHtml($goodsValue->getGoodsName()); ?></td>
                                            <td><?php echo $this->escapeHtml($goodsValue->getGoodsSpec()); ?></td>
                                            <td><?php echo $this->escapeHtml($goodsValue->getGoodsUnit()); ?></td>
                                            <td><?php echo $this->erpCurrencyFormat($goodsValue->getPGoodsPrice()); ?></td>
                                            <td><?php echo $goodsValue->getPGoodsBuyNum(); ?></td>
                                            <td><?php echo $this->erpCurrencyFormat($goodsValue->getPGoodsAmount()); ?></td>
                                        </tr>
                                    <?php } ?>
                                <?php } ?>
                                <tr>
                                    <td colspan="5"></td>
                                    <td colspan="2" class="text-right"><b><?php echo $this->translate('采购金额合计'); ?>：</b><?php echo $this->erpCurrencyFormat($this->payableInfo->getPaymentAmount()); ?></td>
                                </tr>
                                <tr>
                                    <td colspan="5"></td>
                                    <td colspan="2" class="text-right"><b class="text-green"><?php echo $this->translate('已付金额合计'); ?>：</b><?php echo $this->erpCurrencyFormat($this->payableInfo->getFinishAmount()); ?></td>
                                </tr>
                            </table>
                        </div>

                        <div class="box-header no-print">
                            <h4 class="box-title"><?php echo $this->translate('付款记录'); ?></h4>
                        </div>
                        <div class="box-body table-responsive no-padding no-print">
                            <table class="table table-hover">
                                <thead>
                                <tr>
                                    <th width="10%"><?php echo $this->translate('付款时间'); ?></th>
                                    <th width="10%"><?php echo $this->translate('付款金额'); ?></th>
                                    <th width="15%"><?php echo $this->translate('付款人'); ?></th>
                                    <th width="10%"><?php echo $this->translate('付款凭证'); ?></th>
                                    <th width="30%"><?php echo $this->translate('付款备注'); ?></th>
                                    <th width="10%"><?php echo $this->translate('操作人'); ?></th>
                                    <th width="15%"><?php echo $this->translate('操作时间'); ?></th>
                                </tr>
                                </thead>
                                <?php if($this->payableLogList) foreach ($this->payableLogList as $log) { ?>
                                    <tr>
                                        <td><?php echo date("Y-m-d", $log->getPayLogPaytime()); ?></td>
                                        <td><?php echo $this->erpCurrencyFormat($log->getPayLogAmount()); ?></td>
                                        <td><?php echo $this->escapeHtml($log->getPayLogUser()); ?></td>
                                        <td>
                                            <?php if($log->getPayFile()) { ?>
                                                <a href="<?php echo $this->basePath($log->getPayFile()); ?>" title="<?php echo $this->translate('点击查看'); ?>" target="_blank"><i class="fa fa-picture-o"></i></a>
                                            <?php } else echo $this->translate('无') ?>
                                        </td>
                                        <td><?php echo $this->escapeHtml($log->getPayLogInfo()); ?></td>
                                        <td><?php echo $this->escapeHtml($log->getOneAdmin()->getAdminName()); ?></td>
                                        <td><?php echo date("Y-m-d H:i:s", $log->getPayLogAddtime()); ?></td>
                                    </tr>
                                <?php } ?>
                            </table>
                        </div>

                    </div>

                </div>


            </div>
        </div>

    </section>

</div>
<?php
if ($printTemplateArray['state']) {
    echo $this->partial('admin/print-template/inJavascript', [
        'templateBody' => $printTemplateArray['templateBody'],
        'templateCode' => $printTemplateArray['templateCode'],
        'printData' => \Admin\Service\Common\PrintTemplate::payable([
            'payableLog'  => $this->payableLogList,
            'warehouseOrder'  => $this->warehouseOrder,
            'payableInfo'  => $this->payableInfo,
            'orderInfo'     => $this->orderInfo,
            'orderGoods'    => $this->orderGoods,
            'purchaseHelper'   => $this->PurchaseHelper()
        ], $printTemplateArray['templateBody'])]);
}
?>